package com.jiuli_travel.goods_service.controller;


import com.jiuli_travel.goods_service.model.dto.goods.GoodsInsertRequest;
import com.jiuli_travel.goods_service.model.dto.goods.PurchaseGoodsRequest;
import com.jiuli_travel.goods_service.service.IGoodsService;
import com.jiuli_travel.utils.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jiuli
 * @since 2024-05-06
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private IGoodsService goodsService;

    /**
     * 发布商品
     */
    @PostMapping("/publishGoods")
    @Parameters({
            @Parameter(name = "token",description = "请求token",required = true,in = ParameterIn.HEADER),
    })
    public Result publishGoods(@RequestBody GoodsInsertRequest goodsInsertRequest){
        return goodsService.publishGoods(goodsInsertRequest);
    }

    /**
     * 下架商品
     */
    @DeleteMapping("/shelvesGoods")
    @Parameters({
            @Parameter(name = "token",description = "请求token",required = true,in = ParameterIn.HEADER),
    })
    public Result shelvesGoods(Long goodsId){
        return goodsService.shelvesGoods(goodsId);
    }

    /**
     * search商品信息
     */
    @GetMapping("/searchGoods")
    @Parameters({
            @Parameter(name = "token",description = "请求token",required = true,in = ParameterIn.HEADER),
    })
    public Result searchGoods(String searchText, Integer from, Integer size) throws IOException{
        return goodsService.searchGoods(searchText, from, size);
    }
}
